<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    
    <title>第三周作业Ⅱ | Bian&#39;s blog</title>
    <meta name="viewport" content="width=device-width,minimum-scale=1">
    <meta name="generator" content="Hugo 0.75.1" />
    
    
      <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
    

    
    
      <link href="/homework/dist/css/app.4fc0b62e4b82c997bb0041217cd6b979.css" rel="stylesheet">
    

    

    
      

    

    
    
    <meta property="og:title" content="第三周作业Ⅱ" />
<meta property="og:description" content="Method of complements In mathematics and computing, the method of complements is a technique to encode a symmetric range of positive and negative integers in a way that they can use the same algorithm (hardware) for addition throughout the whole range. For a given number of places half of the possible representations of numbers encode the positive numbers, the other half represents their respective additive inverses. The pairs of mutually additive inverse numbers are called complements." />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://Hugh488.gitee.io/homework/posts/the_third_week_2/" />
<meta property="article:published_time" content="2020-09-22T23:35:11+08:00" />
<meta property="article:modified_time" content="2020-09-22T23:35:11+08:00" />
<meta itemprop="name" content="第三周作业Ⅱ">
<meta itemprop="description" content="Method of complements In mathematics and computing, the method of complements is a technique to encode a symmetric range of positive and negative integers in a way that they can use the same algorithm (hardware) for addition throughout the whole range. For a given number of places half of the possible representations of numbers encode the positive numbers, the other half represents their respective additive inverses. The pairs of mutually additive inverse numbers are called complements.">
<meta itemprop="datePublished" content="2020-09-22T23:35:11+08:00" />
<meta itemprop="dateModified" content="2020-09-22T23:35:11+08:00" />
<meta itemprop="wordCount" content="713">



<meta itemprop="keywords" content="" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="第三周作业Ⅱ"/>
<meta name="twitter:description" content="Method of complements In mathematics and computing, the method of complements is a technique to encode a symmetric range of positive and negative integers in a way that they can use the same algorithm (hardware) for addition throughout the whole range. For a given number of places half of the possible representations of numbers encode the positive numbers, the other half represents their respective additive inverses. The pairs of mutually additive inverse numbers are called complements."/>

	
  </head>

  <body class="ma0 avenir bg-near-white">

    
   
  

  <header>
    <div class="bg-black">
      <nav class="pv3 ph3 ph4-ns" role="navigation">
  <div class="flex-l justify-between items-center center">
    <a href="/homework/" class="f3 fw2 hover-white no-underline white-90 dib">
      
        Bian&#39;s blog
      
    </a>
    <div class="flex-l items-center">
      

      
      















    </div>
  </div>
</nav>

    </div>
  </header>



    <main class="pb7" role="main">
      
  
  <article class="flex-l flex-wrap justify-between mw8 center ph3">
    <header class="mt4 w-100">
      <aside class="instapaper_ignoref b helvetica tracked">
          
        POSTS
      </aside>
      




  <div id="sharing" class="mt3">

    
    <a href="https://www.facebook.com/sharer.php?u=https://Hugh488.gitee.io/homework/posts/the_third_week_2/" class="facebook no-underline" aria-label="share on Facebook">
      <svg height="32px"  style="enable-background:new 0 0 67 67;" version="1.1" viewBox="0 0 67 67" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M28.765,50.32h6.744V33.998h4.499l0.596-5.624h-5.095  l0.007-2.816c0-1.466,0.14-2.253,2.244-2.253h2.812V17.68h-4.5c-5.405,0-7.307,2.729-7.307,7.317v3.377h-3.369v5.625h3.369V50.32z   M33,64C16.432,64,3,50.569,3,34S16.432,4,33,4s30,13.431,30,30S49.568,64,33,64z" style="fill-rule:evenodd;clip-rule:evenodd;"/></svg>

    </a>

    
    
    <a href="https://twitter.com/share?url=https://Hugh488.gitee.io/homework/posts/the_third_week_2/&amp;text=%e7%ac%ac%e4%b8%89%e5%91%a8%e4%bd%9c%e4%b8%9a%e2%85%a1" class="twitter no-underline" aria-label="share on Twitter">
      <svg height="32px"  style="enable-background:new 0 0 67 67;" version="1.1" viewBox="0 0 67 67" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M37.167,22.283c-2.619,0.953-4.274,3.411-4.086,6.101  l0.063,1.038l-1.048-0.127c-3.813-0.487-7.145-2.139-9.974-4.915l-1.383-1.377l-0.356,1.017c-0.754,2.267-0.272,4.661,1.299,6.271  c0.838,0.89,0.649,1.017-0.796,0.487c-0.503-0.169-0.943-0.296-0.985-0.233c-0.146,0.149,0.356,2.076,0.754,2.839  c0.545,1.06,1.655,2.097,2.871,2.712l1.027,0.487l-1.215,0.021c-1.173,0-1.215,0.021-1.089,0.467  c0.419,1.377,2.074,2.839,3.918,3.475l1.299,0.444l-1.131,0.678c-1.676,0.976-3.646,1.526-5.616,1.568  C19.775,43.256,19,43.341,19,43.405c0,0.211,2.557,1.397,4.044,1.864c4.463,1.377,9.765,0.783,13.746-1.568  c2.829-1.673,5.657-5,6.978-8.221c0.713-1.716,1.425-4.851,1.425-6.354c0-0.975,0.063-1.102,1.236-2.267  c0.692-0.678,1.341-1.419,1.467-1.631c0.21-0.403,0.188-0.403-0.88-0.043c-1.781,0.636-2.033,0.551-1.152-0.402  c0.649-0.678,1.425-1.907,1.425-2.267c0-0.063-0.314,0.042-0.671,0.233c-0.377,0.212-1.215,0.53-1.844,0.72l-1.131,0.361l-1.027-0.7  c-0.566-0.381-1.361-0.805-1.781-0.932C39.766,21.902,38.131,21.944,37.167,22.283z M33,64C16.432,64,3,50.569,3,34S16.432,4,33,4  s30,13.431,30,30S49.568,64,33,64z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/></svg>

    </a>

    
    <a href="https://www.linkedin.com/shareArticle?mini=true&amp;url=https://Hugh488.gitee.io/homework/posts/the_third_week_2/&amp;title=%e7%ac%ac%e4%b8%89%e5%91%a8%e4%bd%9c%e4%b8%9a%e2%85%a1" class="linkedin no-underline" aria-label="share on LinkedIn">
      <svg  height="32px"  style="enable-background:new 0 0 65 65;" version="1.1" viewBox="0 0 65 65" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <path d="M50.837,48.137V36.425c0-6.275-3.35-9.195-7.816-9.195  c-3.604,0-5.219,1.983-6.119,3.374V27.71h-6.79c0.09,1.917,0,20.427,0,20.427h6.79V36.729c0-0.609,0.044-1.219,0.224-1.655  c0.49-1.22,1.607-2.483,3.482-2.483c2.458,0,3.44,1.873,3.44,4.618v10.929H50.837z M22.959,24.922c2.367,0,3.842-1.57,3.842-3.531  c-0.044-2.003-1.475-3.528-3.797-3.528s-3.841,1.524-3.841,3.528c0,1.961,1.474,3.531,3.753,3.531H22.959z M34,64  C17.432,64,4,50.568,4,34C4,17.431,17.432,4,34,4s30,13.431,30,30C64,50.568,50.568,64,34,64z M26.354,48.137V27.71h-6.789v20.427  H26.354z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>

    </a>
  </div>


      <h1 class="f1 athelas mt3 mb1">第三周作业Ⅱ</h1>
      
      
      <time class="f6 mv4 dib tracked" datetime="2020-09-22T23:35:11+08:00">September 22, 2020</time>

      
      
    </header>
    <div class="nested-copy-line-height lh-copy serif f4 nested-links nested-img mid-gray pr4-l w-two-thirds-l"><h2 id="method-of-complementshttpsenwanweibaikecomwiki-method20of20complements"><a href="https://en.wanweibaike.com/wiki-Method%20of%20complements">Method of complements</a></h2>
<p>In mathematics and computing, the <strong>method of complements</strong> is a technique to encode a symmetric range of positive and negative integers in a way that they can use the same algorithm (hardware) for addition throughout the whole range. For a given number of places half of the possible representations of numbers encode the positive numbers, the other half represents their respective additive inverses. The pairs of mutually additive inverse numbers are called complements. Thus subtraction of any number is implemented by adding its complement. Changing the sign of any number is encoded by generating its complement, which can be done by a very simple and efficient algorithm. This method was commonly used in mechanical calculators and is still used in modern computers. The generalized concept of the radix complement (as described below) is also valuable in number theory, such as in Midy&rsquo;s theorem.</p>
<h2 id="bytehttpsenwanweibaikecomwiki-byte"><a href="https://en.wanweibaike.com/wiki-byte">Byte</a></h2>
<p>The <strong>byte</strong> is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit of memory in many computer architectures. To disambiguate arbitrarily sized bytes from the common 8-bit definition, network protocol documents such as The Internet Protocol refer to an 8-bit byte as an octet.</p>
<h2 id="integer-computer-sciencehttpsenwanweibaikecomwiki-integer20computer20science"><a href="https://en.wanweibaike.com/wiki-Integer%20(computer%20science)">Integer (computer science)</a></h2>
<p>In computer science, an <strong>integer</strong> is a datum of integral data type, a data type that represents some range of mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values. Integers are commonly represented in a computer as a group of binary digits (bits). The size of the grouping varies so the set of integer sizes available varies between different types of computers. Computer hardware, including virtual machines, nearly always provide a way to represent a processor register or memory address as an integer.</p>
<h2 id="floating-pointhttpsenwanweibaikecomwiki-floating20point"><a href="https://en.wanweibaike.com/wiki-Floating%20point">Floating point</a></h2>
<p>In computing, <strong>floating-point</strong> arithmetic is arithmetic using formulaic representation of real numbers as an approximation to support a trade-off between range and precision.</p>
<h2 id="1请证明二进制的负数twos-complement-of-x等于-x-的-ones-complement--1即x每位求反加1">1.请证明：二进制的负数（two‘s complement of X）等于 X 的 ones’ complement ＋ 1（即，X每位求反加1）</h2>
<p><strong>证明：</strong> 令 X = a<sub>0</sub>a<sub>1</sub>a<sub>2</sub>&hellip;a<sub>n</sub>， 则X的补码：a<sub>0</sub>(1-a<sub>1</sub>)(1-a<sub>2</sub>)&hellip;(1-a<sub>n</sub>)+1 ，得X的补码的负数：(1-a<sub>0</sub>)(1-a<sub>1</sub>)(1-a<sub>2</sub>)&hellip;(1-a<sub>n</sub>)+1；</p>
<p>X每一位取反再+1，得 (1-a<sub>0</sub>)(1-a<sub>1</sub>)(1-a<sub>2</sub>)&hellip;(1-a<sub>n</sub>)+1；</p>
<p>显然，两者相等；</p>
<p>得证。</p>
<h2 id="2int8_t-x----017-请用8进制描述变量-x在c中017即017sub8sub">2.Int8_t x = - 017; 请用8进制描述变量 x。在c中017即(017)<sub>8</sub></h2>
<pre><code>先将x转为十进制：
    x = -(1 * (8^1) + 7 * (8^0)) = -15;
则x的原码为：
    10001111；
补码为：
    11110001；
然后将该二进制数转为八进制数：
    0761
</code></pre><p>故应用 <code>0761</code> 来描述 x 。</p>
<h2 id="3-1-c程序int8_t-x---0x1f-int-y--x-请用16进制描述变量-x-和-y并说明-int-y--x-的计算过程">3. (1) C程序：int8_t x = -0x1f; int y = x; 请用16进制描述变量 x 和 y，并说明 int y = x 的计算过程。</h2>
<pre><code>先将x转为十进制：
    x = -(1 * (16^1) + 15 * (16^0)) = -31;
则x的原码为：
    10011111；
补码为：
    11100001；
然后将该二进制数转为八进制数：
    0xe1

y = x,即将x的二进制补码赋值给y, 而y是int, 占32个比特, 故 
    y = 11111111111111111111111111100001；
然后将该二进制数转为八进制数：
    0xffffffe1
</code></pre><p>故应用 <code>0xe1</code> 来描述 x ,
用 <code>0xffffffe1</code> 来描述 y 。</p>
<h2 id="2请用数学证明为什么可以这么计算">(2)请用数学证明，为什么可以这么计算。</h2>
<p><strong>即要证明符号位扩展的正确性</strong></p>
<p><strong>证明：</strong> 令 X = a<sub>0</sub>a<sub>1</sub>a<sub>2</sub>&hellip;a<sub>n</sub> , 则X的补码为 a<sub>0</sub>(1-a<sub>1</sub>)(1-a<sub>2</sub>)&hellip;(1-a<sub>n</sub>)+1 ; 由补码的定义可得 X = a<sub>0</sub>*(-2<sup>n</sup>) + (1-a<sub>1</sub>)*2<sup>n-1</sup> + &hellip; + (1-a<sub>n</sub>)*2<sup>0</sup> + 1</p>
<p>假定将 X 扩展到 n+m 位， 则其补码为 a<sub>0</sub>&hellip;a<sub>0</sub>(1-a<sub>1</sub>)(1-a<sub>2</sub>)&hellip;(1-a<sub>n</sub>)+1 ;
由补码的定义可得</p>
<p>X' = a<sub>0</sub>*(-2<sup>n+m</sup>) + a<sub>0</sub>*(2<sup>n+m-1</sup>) + &hellip; + a<sub>0</sub>*(2<sup>n</sup>) + (1-a<sub>1</sub>)*2<sup>n-1</sup> + &hellip; + (1-a<sub>n</sub>)*2<sup>0</sup> + 1</p>
<p>=a<sub>0</sub>*(-2<sup>n+m</sup> + 2<sup>n+m-1</sup> + 2<sup>n+m-2</sup> + &hellip; + 2<sup>n</sup>) + (1-a<sub>1</sub>)*2<sup>n-1</sup> + &hellip; + (1-a<sub>n</sub>)*2<sup>0</sup> + 1</p>
<p>=a<sub>0</sub>*(-2<sup>n+m</sup> + 2<sup>n</sup> (1 - 2<sup>m</sup>)/(1 - 2) ) + (1-a<sub>1</sub>)*2<sup>n-1</sup> + &hellip; + (1-a<sub>n</sub>)*2<sup>0</sup> + 1</p>
<p>=a<sub>0</sub>*(-2<sup>n</sup>) + (1-a<sub>1</sub>)*2<sup>n-1</sup> + &hellip; + (1-a<sub>n</sub>)*2<sup>0</sup> + 1</p>
<p>可得 X = X' ， 得证</p>
<h2 id="4-nanhttpsenwanweibaikecomwiki-nan">4. <a href="https://en.wanweibaike.com/wiki-NaN">NaN</a></h2>
<p>In computing, <strong>NaN</strong>, standing for <strong>Not a Number</strong>, is a member of a numeric data type that can be interpreted as a value that is undefined or unrepresentable, especially in floating-point arithmetic. Systematic use of NaNs was introduced by the IEEE 754 floating-point standard in 1985, along with the representation of other non-finite quantities such as infinities.</p>
<p>In mathematics, zero divided by zero is undefined as a real number, and is therefore represented by NaN in computing systems. The square root of a negative number is not a real number, and is therefore also represented by NaN in compliant computing systems. NaNs may also be used to represent missing values in computations.</p>
<p>Two separate kinds of NaNs are provided, termed quiet NaNs and signaling NaNs. Quiet NaNs are used to propagate errors resulting from invalid operations or values. Signaling NaNs can support advanced features such as mixing numerical and symbolic computation or other extensions to basic floating-point arithmetic.</p>
<ul class="pa0">
  
</ul>
<div class="mt6 instapaper_ignoref">
      
      
      </div>
    </div>

    <aside class="w-30-l mt6-l">




</aside>

  </article>

    </main>
    <footer class="bg-black bottom-0 w-100 pa3" role="contentinfo">
  <div class="flex justify-between">
  <a class="f4 fw4 hover-white no-underline white-70 dn dib-ns pv2 ph3" href="https://Hugh488.gitee.io/homework" >
    &copy;  Bian's blog 2020 
  </a>
    <div>














</div>
  </div>
</footer>

    

  <script src="/homework/dist/js/app.3fc0f988d21662902933.js"></script>


  </body>
</html>
